package com.spzx.cart.controller;

import com.spzx.product.api.domain.CartItem;
import com.spzx.cart.service.CartService;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.security.annotation.InnerAuth;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping
@Tag(name = "购物车模块")
public class CartController extends BaseController {
    @Resource
    CartService cartService;
    @Operation(summary = "内部调用接口：提交订单 删除用户购物车中选中的购物项")
    @InnerAuth
    @GetMapping("delCheckedCartItems")
    public R<Boolean> delCheckedCartItems(){
        return R.ok(cartService.delCheckedCartItems());
    }
    @Operation(summary = "内部调用接口：查询结算页需要的购物项列表")
    @InnerAuth
    @GetMapping("getCheckedCartItems")
    public R<List<CartItem>> getCheckedCartItems(){
        return R.ok(cartService.getCheckedCartItems());
    }
    //("/cart/addToCart/8/1")
    @Operation(summary = "加购")
    @GetMapping("/addToCart/{skuId}/{skuNum}")
    public AjaxResult addToCart(@PathVariable("skuId")Long skuId,
                                @PathVariable("skuNum")Integer skuNum ){
        return toAjax(cartService.add2Cart(skuId,skuNum));
    }

    @Operation(summary = "查询购物车")
    @GetMapping("/cartList")
    public AjaxResult cartList(){
        return success(cartService.cartList());
    }
    //deleteCart/8
    @Operation(summary = "查询购物车")
    @DeleteMapping("/deleteCart/{skuId}")
    public AjaxResult deleteCart(@PathVariable("skuId")Long skuId){
        return toAjax(cartService.deleteCart(skuId));
    }
    ///checkCart/1/1
    @Operation(summary = "切换购物项选中状态")
    @GetMapping("/checkCart/{skuId}/{status}")
    public AjaxResult checkCart(@PathVariable("skuId")Long skuId,
                                 @PathVariable("status")Integer status ){
        return toAjax(cartService.checkCart(skuId,status));
    }
    ///allCheckCart/1
    @Operation(summary = "切换所有购物项选中状态")
    @GetMapping("/allCheckCart/{status}")
    public AjaxResult allCheckCart(@PathVariable("status")Integer status ){
        return toAjax(cartService.allCheckCart(status));
    }
    ///clearCart
    @Operation(summary = "清空购物车")
    @GetMapping("/clearCart")
    public AjaxResult clearCart( ){
        return toAjax(cartService.clearCart());
    }
}
